"""
network.py

Thu Oct 11 11:06:08 CEST 2012

create an autoassociative random network as described in 
Gibson & Robinson (1992). It consists of
a network of excitatory neurons interconnected with a constant 
random probability. 

Because the neurons are interconnected, the connectivity matrix W is a 
cuadratic matrix of size nxn, being n the number of excitatory neurons. 
Every element in the matrix (Wij) is an independent random variable that 
takes the value one if the neuron j sends a projection to the neuron i or
 zero elsewhere. It is assumed that neurons do not make projections to
themselves (e.g every W_ij element where i=j is zero. The probability that 
Wij takes the value one is assumed to be constant (c).   

P(W_ij= 1)= c
P(W_ij= 0)= 1-c

You do not need to import the Topology class to create the random matrix,
simply import a topology object, because upon calling the object will 
return a random matrix:
>>> from network import topology
>>> W = topology(n = 3000, c=0.5) # 3000 neurons with connection prob. 50%
"""

from cutils import randmatrix

class Topology(object):
    """ 
    create connectivity matrix as described in Gibson & Robinson (1992).
    This consists of a matrix W of size nxn, where n is the number of
    excitatory neurons. Every element of the matrix (W_ij) is a random
    variable that take the value one if the neuron i is connected to 
    the neuron j in the network, or zero elsewhere. The probability of

    W_ij =1 is a constant (c). 
    """
    def __init__(self):
        """
        Object constructor
        """
        self._n = None
        self._c = None 
        self._cmatrix = None 


    def __call__(self, n, c, seed=None):
        """
        n       -- number of principal excitatory neurons
        c       -- connectivity, probability that 2 neurons are connected
        seed    -- seed, None if no seed is given

        returns a NumPy array with the connectivity matrix
        not an object!!!

        Provide a seed if you want to have comparable results

        Example:
        >>> from network import topology
        >>> W = topology(n=300, c=0.028, seed=100)
        """
        self._n = n
        self._c = c
        # the connectivity matrix (W in Gibson & Robinson, 1992)
        return randmatrix(n, c, seed)

# create objects
topology = Topology()

if __name__ == '__main__':
    pass
